package com.sff.site.connector {
	
	import com.sff.core.sff_internal;
	import com.sff.site.tree.SiteTree;
	import com.sff.site.tree.TreesProvider;
	
	import flash.events.Event;

	public class TreeConnector {
		
		protected var _devices : Array;
		
		public function TreeConnector() {
			_devices = new Array();
		}

		sff_internal function connectDevice( device : String ) : void {
			if( _devices.indexOf( device ) > -1 ) {
				return;
			}
			
			var siteTree: SiteTree = TreesProvider.sff_internal::getTree( device );
			siteTree.addEventListener( SiteTree.PATH_CHANGE, onPathChange );
			
			_devices.push(device);
			deviceAdded(device);
		}

		sff_internal function disconnectDevice( device : String ) : void {
			var index : int = _devices.indexOf(device);
			if( index != -1 ) {
				var siteTree: SiteTree = _devices[ index ];
				siteTree.removeEventListener( SiteTree.PATH_CHANGE, onPathChange );
				
				_devices.splice( index , 1 );
			}
		}		
		
		protected function deviceAdded(device : String) : void {
			// abstract
		}
		
		protected function onPathChange( e : Event ) : void {
			// abstract
		}
	}
}
